package com.orangelife.mobile.login.biz;

import android.os.Handler;

import com.curry.android.http.OrangeDataHandler;
import com.curry.android.http.OrangeErrorHandler;
import com.curry.android.http.VolleyHttpUtil;
import com.orangelife.mobile.constants.Constant;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * 对应Login2Activity的登录业务逻辑
 * <p/>
 * Created by wgf on 2016/3/30.
 *
 * @author wgf
 * @since v3.6.0
 */
public class LoginHttpBiz {

    public static void loginWithPassword(String phone, String password, int what, Handler handler) {
        HashMap<String, Object> jsonMap = new HashMap<>();
        jsonMap.put("userName", LoginBiz.encryptPhone(phone));
        jsonMap.put("password", LoginBiz.encryptPassword(password));
        jsonMap.put("loginType", "app");
        VolleyHttpUtil.getInstance().postWithHandler(Constant.PATH_LOGIN, jsonMap, handler, what);
    }

    public static void loginWithVerifyCode(String phone, String verifyCode, int what, Handler handler) {
        HashMap<String, Object> jsonMap = new HashMap<>();
        jsonMap.put("memberName", LoginBiz.encryptPhone(phone));
        jsonMap.put("verifyCode", verifyCode);
        jsonMap.put("useType", "4");
        VolleyHttpUtil.getInstance().postWithHandler(Constant.PATH_VALCODE_LOGIN, jsonMap, handler, what);
    }


    /**是否隐藏语音验证码登入方式*/
    public static void voiceCodeState( int what, Handler handler) {
        HashMap<String, String> jsonMap = new HashMap<>();
        VolleyHttpUtil.getInstance().getWithHandler(Constant.PATH_VOICE_CODE_STATE, handler, what ,jsonMap);
    }

    public static Map<String, Object> handleLogin(Object response, String errInfo, String okInfo) {
        if (OrangeErrorHandler.getInstance().isSuccess(response, errInfo, okInfo)) {
            if (response instanceof JSONObject) {
                return OrangeDataHandler.getMapWithEntityNoGson((JSONObject) response);
            }
        }
        return null;
    }

}
